package common

import (
	"sync"

	"gitee.com/tomatomeatman/golang-repository/bricks3/function/configutil"
	"github.com/gin-gonic/gin"
)

var (
	mainDb     string    //主库名
	mainDbOnce sync.Once //单次赋值操作
)

// 获取主库名
func GetMainDb() string {
	mainDbOnce.Do(func() {
		mainDb = configutil.ReadConfigKey("", "DataSource", "MainDb", "").(string)
	})

	return mainDb
}

func CurrentLoginUserId(ctx *gin.Context) string {
	ctx.Request.ParseForm() //警告:必须先 解析所有请求数据

	form := ctx.Request.Form
	if form == nil {
		return ""
	}

	return form.Get("loginUserId")
}
